/**************************************************************************
 * Copyright (C) 2017-2017  Unisound
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 **************************************************************************
 *
 * Description : uni_hal_audio_buf.h
 * Author      : wufangfang@unisound.com
 * Date        : 2020.01.08
 *
 **************************************************************************/
#ifndef HAL_INC_UNI_AUDIO_BUF_H_
#define HAL_INC_UNI_AUDIO_BUF_H_

#ifdef __cplusplus
extern "C" {
#endif

typedef void * AudioBufHandler;

/**
 * Usage:   Creat a ping-pong buffer for DMA audio player
 * Params:  size:   szie of one block
 * Return:  handler that point to a ping-pong buffer
 */
AudioBufHandler uni_audio_buf_create(int size);

/**
 * Usage:   Destroy a ping-pong buffer
 * Params:  handler:  handler that point to a ping-pong buffer
 * Return:  None
 */
void uni_audio_buf_destroy(AudioBufHandler handler);

/**
 * Usage:   Inject data to ping-pong buffer, will blocked if buffer is full
 * Params:  handler:  handler that point to a ping-pong buffer
 *          buf:      buffer of data
 *          size:     size of data, will append 0 if less than block
 * Return:  size of write
 */
int uni_audio_buf_write(AudioBufHandler handler,
                               const char *buf, int size);

/**
 * Usage:   Get read buffer adderss of ping-pong buffer,
 *          return 0 full buffer if there is not valid data
 * Params:  handler:  handler that point to a ping-pong buffer
 *          psize:    point for save size number
 * Return:  point to data than can be read
*/
const char *uni_audio_buf_read(AudioBufHandler handler, int *psize);

#ifdef __cplusplus
}
#endif
#endif

